package org.agora.games.bodybuilder;


import svg.parser.Vertex;


public class Pixel {

    public static final int NORTH = 1;
    public static final int SOUTH = -1;
    public static final int EAST = 1;
    public static final int WEST = -1;
    public static final int CENTRE = 0;

    public int x;
    public int y;
    private int nspX = -1;
    private int nspY = 0;

    public Pixel(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public Pixel(int x, int y, int nspX, int nspY) {
        this.x = x;
        this.y = y;

        this.nspX = nspX;
        this.nspY = nspY;
    }

    public void set(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public Pixel add(Pixel p) {
        return new Pixel(x + p.x, y + p.y);
    }

    public Pixel sub(Pixel p) {
        return new Pixel(x - p.x, y - p.y);
    }

    public Vector2 toVec2() {
        return new Vector2(x, y);
    }

    public Vertex toVertex() {
        return new Vertex(x, y);
    }

    public Pixel mult(int i) {
        return new Pixel(x * i, y * i);
    }

    public String toString() {
        return "x:" + x + " y:" + y;
    }

    public void setNSP(Pixel p) {
        nspX = p.x;
        nspY = p.y;
    }

    public Pixel clockwise() {
        Pixel nsp = clockwise(nspX, nspY);
        nspX = nsp.x;
        nspY = nsp.y;
        return add(nsp);
    }


    public Pixel clockwise(int x, int y) {
        return clockwise(new Pixel(x, y));
    }

    public Pixel clockwise(Pixel sp) {
        if (sp.x == WEST) {
            if (sp.y == SOUTH)
                return new Pixel(WEST, CENTRE);
            else if (sp.y == CENTRE)
                return new Pixel(WEST, NORTH);
            else if (sp.y == NORTH)
                return new Pixel(CENTRE, NORTH);
        }

        if (sp.x == CENTRE) {
            if (sp.y == SOUTH)
                return new Pixel(WEST, SOUTH);
            else if (sp.y == NORTH)
                return new Pixel(EAST, NORTH);
        }

        if (sp.x == EAST) {
            if (sp.y == SOUTH)
                return new Pixel(CENTRE, SOUTH);
            else if (sp.y == CENTRE)
                return new Pixel(EAST, SOUTH);
            else if (sp.y == NORTH)
                return new Pixel(EAST, CENTRE);
        }
        return null;
    }


    public Pixel clockwise2(Pixel sp) {
        if (sp.x == -1) {
            if (sp.y == -1)
                return new Pixel(-1, 0);
            else if (sp.y == 0)
                return new Pixel(-1, 1);
            else if (sp.y == 1)
                return new Pixel(0, 1);
        }

        if (sp.x == 0) {
            if (sp.y == -1)
                return new Pixel(-1, -1);
            else if (sp.y == 1)
                return new Pixel(1, 1);
        }

        if (sp.x == 1) {
            if (sp.y == -1)
                return new Pixel(0, -1);
            else if (sp.y == 0)
                return new Pixel(1, -1);
            else if (sp.y == 1)
                return new Pixel(1, 0);
        }
        return null;
    }

    public boolean equals(Pixel p) {
        if (x == p.x && y == p.y)
            return true;
        return false;
    }
}
